package leetcode.binarysearch;

import java.util.TreeSet;

public class Lc475 {



    public int findRadius(int[] houses, int[] heaters) {

        TreeSet<Integer> set = new TreeSet<>();
        for (int i = 0; i < heaters.length; i++) {
            set.add(heaters[i]);
        }
        int ans = 0;
        for (int i = 0; i < houses.length; i++) {
            Integer left = set.floor(houses[i]);
            Integer right = set.ceiling(houses[i]);
            int minDis = Integer.MAX_VALUE;
            if (left != null) {
                minDis = houses[i] - left;
            }
            if (right != null) {
                minDis = Math.min(right - houses[i], minDis);
            }
            ans = Math.max(ans, minDis);
        }
        return ans;
    }

    public static void main(String[] args) {
        Lc475 lc475 = new Lc475();
        int[] h1 = {1,2,3};
        int[] h2 = {2};
        System.out.println(lc475.findRadius(h1, h2));
    }
}
